package com.zou.recruit.controller;

import com.zou.recruit.entity.User;
import com.zou.recruit.mapper.UserMapper;
import com.zou.recruit.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * @author: 邹祥发
 * @date: 2021/9/22 15:10
 */
@Controller
public class ResumeController {

    @Resource
    private UserMapper userMapper;

    //修改用户简历信息页（跳转页面）
    @RequestMapping(value = "/resume", method = RequestMethod.GET)
    public String userInfo(Model model, HttpSession session) {
        //通过session获取登录的用户名
        String name = (String) session.getAttribute("user");
        //根据用户名查找该用户的详细信息
        User userIn = userMapper.selectAllByName(name);
        System.out.println("++++++++"+userIn);
        model.addAttribute("userIn", userIn);

        return "user/resume";
    }

    //修改方法（更新数据）
    @RequestMapping(value = "/editResume", method = RequestMethod.POST)
    public String edit(@RequestParam("telephone") String telephone,
                       @RequestParam("birthday") String birthday,
                       @RequestParam("mail") String mail,
                       @RequestParam("sex") String sex,
                       @RequestParam("status") String status,
                       @RequestParam("intention") String intention,
                       @RequestParam("experience") String experience,
                       @RequestParam("advantage") String advantage,
                       @RequestParam("project") String project,
                       @RequestParam("education") String education,
                       @RequestParam("salary") String salary,
                       HttpSession session) {
        //通过session获取登录的用户名详细信息
        String username = (String) session.getAttribute("user");

        userMapper.updateResume(telephone,birthday,mail,sex,status,intention,experience,advantage,project,education,salary,username);

        return "redirect:resume";
    }
}
